<template>
  <div class="container">
    <!--标题-->
    <van-nav-bar title="订单详情" left-arrow>
      <template #left>
        <van-icon name="cross" @click="closePopup" />
      </template>
    </van-nav-bar>
    <!--内容-->
    <div class="content-top">
      <!--top-->
      <div class="top">
        <!--top-Text-->
        <div class="top-text">
          <div class="left">
            <img :src="orderItme.logo" alt="" />
            <span>{{ orderItme.platform }}</span>
          </div>
          <div class="right">
            <span>00000001</span>
          </div>
        </div>
        <!--top-State-->
        <div class="top-state">
          <div class="state-buying" v-if="orderItme.state === '未出单'">
            <span>正在拼团,截止</span>
            <van-count-down :time="time" format="mm:ss" class="countDown" />
          </div>
          <div class="state-nobuy" v-else>
            <div
              :class="{ leftboxchosing: chosing, leftboxnochosing: !chosing }"
              @click="changeBoxClass"
            >
              <span>零售</span>
            </div>
            <div
              :class="{
                rightboxchosing: changeTextAndClass,
                rightboxnochosing: !changeTextAndClass,
              }"
              @click="changeTextAndBoxClass"
            >
              <span v-text="changeTextAndClass ? '优品' : '双/件'"></span>
            </div>
          </div>
        </div>
      </div>
      <!--bottom-->
      <div class="content-bottom">
        <!--info-->
        <div class="bottom-info">
          <van-cell>
            <template #title>
              <span>购买金额：300</span>
            </template>
            <template #default>
              <span>盈利金额：</span
              ><span :class="{ text: orderItme.state.startsWith('+') }">{{
                orderItme.state
              }}</span>
            </template>
          </van-cell>
          <van-cell>
            <template #title>
              <span>购买时间：{{ orderItme.date }}</span>
            </template>
          </van-cell>
          <van-cell>
            <template #title>
              <span>订单编号：</span>
              <span>{{ orderItme.orderNumber }}</span>
              <img src="~@/assets/orderSvg/复制.svg" @click="copyOrderNumber" />
            </template>
          </van-cell>
          <!--orderlist-->
          <div class="bottom-orderlist">
            <table class="tab" cellspacing="0">
              <thead>
                <tr>
                  <th>购买数量</th>
                  <th>购买数量</th>
                  <th>购买数量</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="item in orderItme.orderInfo" :key="item.id">
                  <td>{{ item.type }}</td>
                  <td>{{ item.number }}</td>
                  <td>{{ item.total }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "OrderInfo",
  props: {
    orderItme: {
      required: true,
    },
  },
  data() {
    return {
      time: 5 * 60 * 1000,
      orderDate: this.$dayjs(new Date()).format("YYYY-MM-DD hh:mm:ss"),
      chosing: true,
      changeTextAndClass: true,
    };
  },
  methods: {
    copyOrderNumber() {
      var cInput = document.createElement("input");
      cInput.value = this.orderItme.orderNumber;
      document.body.appendChild(cInput);
      cInput.select(); // 选取文本框内容
      document.execCommand("copy");
      this.$toast.success("复制成功");
      document.body.removeChild(cInput);
    },
    changeBoxClass() {
      this.chosing = !this.chosing;
    },
    changeTextAndBoxClass() {
      this.changeTextAndClass = !this.changeTextAndClass;
    },
    closePopup() {
      this.$emit("closePopup");
    },
  },
};
</script>
<style scoped lang="less">
.top {
  margin-top: 10px;
  height: 220px;
  background-color: #fff;
  .top-text {
    display: flex;
    align-items: center;
    padding: 20px;
    .left {
      width: 90%;
      display: flex;
      align-items: center;
      font-size: 32px;
      span {
        margin-left: 10px;
      }
    }
    .right {
      font-size: 14px;
    }
  }
  .top-state {
    width: 378px;
    margin: 0 auto;
    .state-buying {
      display: flex;
      justify-content: center;
      width: 378px;
      height: 80px;
      border: 0.5px solid #e0d7d7;
      background-image: linear-gradient(180deg, #ffffff, #fdfdfd, #fcfafa);
      border-radius: 40px;
      text-align: center;
      line-height: 80px;
      span {
        font-size: 32px;
      }
      .countDown {
        margin-left: 10px;
        line-height: 80px;
        font-size: 32px;
      }
    }
    .state-nobuy {
      display: flex;
      justify-content: space-between;
      width: 378px;
      height: 80px;
      .leftboxchosing {
        width: 160px;
        height: 80px;
        border-radius: 40px;
        border: 1px solid #ffffff34;
        background-image: linear-gradient(181deg, #fa7d22, #fa461b);
        text-align: center;
        line-height: 80px;
        span {
          font-size: 32px;
          color: #fff;
        }
      }
      .leftboxnochosing {
        width: 160px;
        height: 80px;
        border-radius: 40px;
        border: 1px solid #bcc5dc;
        background-image: linear-gradient(180deg, #ffffff, #f2f3fd, #fafbfc);
        text-align: center;
        line-height: 80px;
        span {
          font-size: 32px;
          // color: #fff;
        }
      }
      .rightboxchosing {
        width: 160px;
        height: 80px;
        border-radius: 40px;
        border: 1px solid #ffffff34;
        background-image: linear-gradient(181deg, #fa7d22, #fa461b);
        text-align: center;
        line-height: 80px;
        span {
          font-size: 32px;
          color: #fff;
        }
      }
      .rightboxnochosing {
        width: 160px;
        height: 80px;
        border-radius: 40px;
        border: 1px solid #bcc5dc;
        background-image: linear-gradient(180deg, #ffffff, #f2f3fd, #fafbfc);
        text-align: center;
        line-height: 80px;
        span {
          font-size: 32px;
          // color: #fff;
        }
      }
    }
  }
}
.content-bottom {
  span {
    font-size: 28px;
    color: #323233;
  }
  .bottom-info {
    .text {
      font-size: 28px;
      color: #f56c7d;
    }
  }
  input {
    width: 280px;
    border: 0;
  }
  img {
    vertical-align: middle;
  }
  .bottom-orderlist {
    padding: 20px;
    .tab {
      width: 100%;
      background-color: #fff;
      font-size: 28px;
      text-align: center;
      border-radius: 12px;
      border: 1px solid #e2e2e2;
      thead {
        tr {
          height: 66px;
          background-color: #fcf0f0;
        }
      }
      tbody {
        tr {
          height: 66px;
          &:nth-child(2n) {
            background-color: #e2e2e2;
          }
        }
      }
    }
  }
}
</style>
